package org.seckill.TestSpring;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;

/**
 * Created by wangyg 
 * on 2017/4/21 15:05
 */
public class BeanFactoryAwareHelper implements BeanFactoryAware {
	private static BeanFactory beanFactory;

	public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
		this.beanFactory = beanFactory;
	}

	public static <T> T getBean(String beanName, Class<T> clz) {
		if (beanFactory == null) {
			throw new NullPointerException("BeanFactory is null!");
		}
		T bean = (T) beanFactory.getBean(beanName);
		return bean;
	}
}
